using Box2DSharp.Testbed.Unity.Inspection;
using Box2DSharp.Testbed.Unity;
using LitJson;
using System.Collections;
using System.Collections.Generic;
using Testbed.Abstractions;
using Testbed.TestCases;
using UnityEngine;
using Box2DSharp.Common;
using System.Reflection;
using System.Threading;
using Box2DSharp.Dynamics;
using UnityEngine.InputSystem;
using UnityEngine.EventSystems;
using cframework.lockstep;
using static UnityEngine.EventSystems.EventTrigger;



public class TestTimerAndCoroutine : MonoBehaviour
{
    public int serverHerz = 15;
    public int clientHerz = 30;
    //HelloWorld test;
    LockStepWorld fuw = new LockStepWorld();
    





    void Start()
    {
        //test = new HelloWorld();
        //var Settings = TestSettingHelper.Load();
        //Settings.Hertz = clientHerz;
        //Global.Settings = Settings;
        //Global.Camera.Width = Settings.WindowWidth;
        //Global.Camera.Height = Settings.WindowHeight;

        //var unityDrawer = UnityDrawer.GetDrawer();
        //var DebugDrawer = new DebugDrawer { Drawer = unityDrawer, ShowUI = true };
        //Global.DebugDrawer = DebugDrawer;
        //test.Input = Global.Input;
        //test.Drawer = Global.DebugDrawer;
        //test.TestSettings = Global.Settings;
        //test.World.Drawer = Global.DebugDrawer;
        //test.TextIncrement = 20;



        fuw.clientHerz = clientHerz;
        fuw.serverHerz = clientHerz;
        fuw.ignoreServerMsg = true;
        fuw.serverMsgBeginIndex = 0;
        fuw.processClientStepCallback = ProcessClientStep;
        fuw.processServerStepCallback = ProcessServerStep;
        fuw.processWaitMsgStepCallback = ProcessWaitMsgStep;
        fuw.StartWorld();

    }






    protected void FixedUpdate()
    {
        this.fuw.UpdateStep();
    }


    protected void ProcessWaitMsgStep(float clientTime, float deltaTime)
    {

    }

    protected void ProcessServerStep(int _serverFrameIndex, FP serverTime, FP deltaTime, object msgObj)
    {
        

    }

    protected void ProcessClientStep(int _clientFrameIndex, FP clientTime, FP deltaTime)
    {
        if(clientTime == 0)
        {
            GameObject.CreatePrimitive(PrimitiveType.Sphere).AddComponent<TestLockStepBehaviour>();
        }

        //test.Step();
    }


    private void OnPreRender()
    {
        //if (test.TestSettings == null)
        //{
        //    return;
        //}


        //test.Render();
    }

}
